package com.dailyblue.java.standard.design.代理模式.jdk动态代理;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

// 代理接口
public class JDK2DynamicProxy implements InvocationHandler {
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println(method.getName());
        if(method.getName().equals("save")){
            System.out.println("save方法执行了");
        }else if(method.getName().equals("update")){
            System.out.println("update方法执行了");
        }
        System.out.println("代理对象开始执行");
        System.out.println("代理类完善了接口的操作");
        System.out.println("代理对象执行完毕");
        return null;
    }

    public <T> T getMapper(Class<T> c) {
        T treat = (T) Proxy.newProxyInstance(c.getClassLoader(), new Class[]{c}, this);
        return treat;
    }
}
